package com.hy.logtrace.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hy.logtrace.domain.TraceWrapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TraceWrapperAutoConfiguration {

    @Bean
    @ConditionalOnBean(ObjectMapper.class) // 只有当项目中存在 ObjectMapper Bean 时才创建 TraceWrapper
    public TraceWrapper traceWrapper(ObjectMapper objectMapper) {
        return new TraceWrapper(objectMapper);
    }

    @Bean
    @ConditionalOnMissingBean(ObjectMapper.class) // 如果项目中没有定义 ObjectMapper，则创建默认实例
    public ObjectMapper defaultObjectMapper() {
        return new ObjectMapper();
    }
}